package com.example.warehouse.bus.service.impl;

import com.example.warehouse.bus.dao.persist.repository.IBusOutportRepository;
import com.example.warehouse.bus.pojo.entity.BusInport;
import com.example.warehouse.bus.pojo.entity.BusOutport;
import com.example.warehouse.bus.pojo.param.BusOutportAddNewParam;
import com.example.warehouse.bus.pojo.param.BusOutportUpdateParam;
import com.example.warehouse.bus.pojo.vo.BusInportListItemVO;
import com.example.warehouse.bus.pojo.vo.BusOutportListItemVO;
import com.example.warehouse.bus.service.IBusOutportService;
import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.security.CurrentPrincipal;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 安康
 * @Date 2023/7/15 23:41
 * @Version 1.0
 */
@Slf4j
@Service
public class IBusOutportServiceImpl implements IBusOutportService {

    /*默认的查询每页条目数大小*/
    @Value("${warehouse.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;
    @Autowired
    IBusOutportRepository iBusOutportRepository;


    /**
     * 新增退货数据实现类方法
     * @param busOutportAddNewParam
     * @return 增加条目数
     */
    @Override
    public int insert(BusOutportAddNewParam busOutportAddNewParam) {
        log.debug("新增退货数据,ServiceImpl,参数:新增退货参数类:{}",busOutportAddNewParam);
        BusOutport busOutport = new BusOutport();
        BeanUtils.copyProperties(busOutportAddNewParam,busOutport);

        int row = iBusOutportRepository.insert(busOutport);
        return row;
    }

    /**
     * 删除退货数据实现类方法
     * @param currentPrincipal
     * @return
     */
    @Override
    public int deleteById( Long id,CurrentPrincipal currentPrincipal) {
        log.debug("新增退货,repository,参数:id:{},最近当事人:{}",id, currentPrincipal);

        return iBusOutportRepository.deleteById(id,currentPrincipal);
    }

    /**
     * 根据id修改退货数据
     * @param id
     * @param busOutportUpdateParam
     * @return
     */
    @Override
    public int updateById(Long id, BusOutportUpdateParam busOutportUpdateParam) {
        log.debug("新增退货,repository,参数:id:{},最近当事人:{}",id, busOutportUpdateParam);

        return iBusOutportRepository.updateById(id,busOutportUpdateParam);
    }

    /**
     * 退货数据列表--查,默认每页显示数
     * @param pageNum 页码
     * @return
     */
    @Override
    public PageData<BusOutportListItemVO> list(Integer pageNum) {
        log.debug("开始处理【查询退货列表】的业务，页码：{}", pageNum);
        PageData<BusOutportListItemVO> pageData= iBusOutportRepository.list(pageNum,defaultQueryPageSize);
        return pageData;
    }

    /**
     * 查询退货数据列表--查,根据用户传入每页显示数
     * @param pageNum 页码
     * @param pageSize 每页记录数
     * @return
     */
    @Override
    public PageData<BusOutportListItemVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始处理【查询退货列表】的业务，页码：{}，每页记录数：{}", pageNum, pageSize);

        PageData<BusOutportListItemVO> pageData=iBusOutportRepository.list(pageNum,pageSize);
        return pageData;
    }

    @Override
    public List<BusOutport> selectAllOut() {
        List<BusOutport> list = iBusOutportRepository.selectAllOut();
        return list;
    }
}
